package com.hncc.kumao.util;

import javax.servlet.http.HttpServletRequest;

public class JSONUtils {

    public static String getJsonByRequest(HttpServletRequest request) {
        String jsonString = "";
        try {
            int contentLength = request.getContentLength();
            if (contentLength < 0) {
                return null;
            }
            byte buffer[] = new byte[contentLength];
            for (int i = 0; i < contentLength;) {
                int len = request.getInputStream().read(buffer, i, contentLength - i);
                if (len == -1) {
                    break;
                }
                i += len;
            }
            jsonString = new String(buffer, "utf-8");
        } catch (Exception e) {
            e.printStackTrace();
        }
        return jsonString;
    }
}
